/*
 * @Author: your name
 * @Date: 2020-10-28 10:58:43
 * @LastEditTime: 2020-11-10 17:07:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /crowd-funding/src/utils/constants.js
 */
// import { isApp, getUrlQuery, getUUID } from "@jmfe/jm-common"
import { getUUID, getUrlQuery, isApp } from '@jmfe/jm-common'
import cookie from '@jmfe/jm-cookie'

export const UUID = getUUID() || cookie.get('mba_muid') || ''

// 微信和QQ中才需要额外申请
export const WQ_BIZ = ''

// export const pin = cookie.get('pt_pin') || 'not_login'
// 获取项目ID
export const projectId = getUrlQuery('projectId') || ''
// 获取来源
export const source = getUrlQuery('source') || ''

export const shareUrl = () => {
	const url = location.href
	let resultUrl = ''
	// 判断是否包含projectId
	if (url.includes('projectId')) {
		// 判断是否包含source字段
		if (url.includes('source')) {
			const [noSourceUrl] = url.split('&source')
			resultUrl = `${noSourceUrl}&source=jdshare`
		} else {
			resultUrl = `${url}&source=jdshare`
		}
	} else {
		console.log('分享链接缺少参数！')
		return
	}
	return resultUrl
}
/**
 * 按钮状态
 * btnStatus_按钮状态(1 去预约 ,2立即支持 ,3众筹成功结束 ,4众筹失败结束 ,5购买现货)
 * reminderStatus_提醒组件状态(false/true,未添加/已添加)_isJDAPP(0/1 非京东/京东)
 *
 */
export const getBtnStatus = (btnStatus, reminderStatus) => {
	let event = ''
	let image = ''
	if (isApp('jd') && reminderStatus === null) {
		return {
			image,
			event,
		}
	}
	if (btnStatus === 1 && !reminderStatus) {
		if (isApp('jd')) {
			image =
				'https://img13.360buyimg.com/imagetools/jfs/t1/148757/21/13337/12775/5fa3c302Ed19c919e/ac0b4895c1c30557.png'
			event = { type: 'add:reminder' }
		} else {
			image =
				'https://img12.360buyimg.com/imagetools/jfs/t1/152518/37/4856/13131/5fa3c302E0b92cfcd/54fa542e04d31e7f.png'
		}
	} else if (btnStatus === 1 && reminderStatus) {
		if (isApp('jd')) {
			image =
				'https://img11.360buyimg.com/imagetools/jfs/t1/143413/27/13320/13078/5fa3c302E972865ec/76b6644fb23fd202.png'
		} else {
			image =
				'https://img12.360buyimg.com/imagetools/jfs/t1/152518/37/4856/13131/5fa3c302E0b92cfcd/54fa542e04d31e7f.png'
		}
	} else if (btnStatus === 2) {
		image =
			'https://img14.360buyimg.com/imagetools/jfs/t1/129021/20/17538/12871/5fa3c302E4c1a7aca/dfcc42e5eb539c22.png'
		event = { type: 'open:dialog', payload: { isOpen: true } }
	} else if (btnStatus === 3) {
		image =
			'https://img11.360buyimg.com/imagetools/jfs/t1/137638/24/13324/12289/5fa3c302E758f81af/0aa58b9620f0d199.png'
	} else if (btnStatus === 4) {
		image =
			'https://img11.360buyimg.com/imagetools/jfs/t1/137638/24/13324/12289/5fa3c302E758f81af/0aa58b9620f0d199.png'
	} else {
		image =
			'https://img12.360buyimg.com/imagetools/jfs/t1/152518/37/4856/13131/5fa3c302E0b92cfcd/54fa542e04d31e7f.png'
	}
	return {
		image,
		event,
	}
}

// 网络请求结果枚举
export const ErrorType = {
	SUCCESS_TYPE: {
		code: 0,
		message: '网络请求成功',
	},
	NO_WIFI_TYPE: {
		code: -1,
		btnTitle: '重新加载',
		img:
			'https://img11.360buyimg.com/imagetools/jfs/t1/129529/40/17558/19159/5fa3c2e4E026c84e3/60032efe9f79a59e.png',
		message: '网络请求失败',
	},
	NO_DATA_TYPE: {
		code: -2,
		message: '暂无数据',
		btnTitle: '回众筹首页',
		reloadAction() {
			window.location.replace(`https://jddx.jd.com/m/jddnew/zc.html?_ts=${Date.now()}`)
		},
		img:
			'https://img12.360buyimg.com/imagetools/jfs/t1/134169/12/14793/17567/5fa3c2bcE20fb5a56/56f8619f450bbca4.png',
	},
}

// 占位图
export const placeHolderImg =
	'https://m.360buyimg.com/babel/jfs/t1/126631/36/13782/4597/5f73254bEb32eb288/f6d7327c6fbedb5c.png'

// 沉浸式头部配置
export const navData = {
	canPull: '0',
	supportTran: '1',
	tranParams: {
		whiteImg:
			'https://m.360buyimg.com/babel/jfs/t1/114764/11/2591/927/5ea2c2ffE4af3cd95/29aee90c6cb4f0d1.png',
		blackImg: '',
		backgroundColor: '',
		naviMenuType: 'wb',
	},
}
